package com.itheima.day10;

import com.itheima.domain.Student;
import com.itheima.util.RandomUtil;

import java.time.Period;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;

/*
最大三个年纪的
最小三个年纪的
最大年纪的人和最小年纪的人是谁，差多久?
 */
public class Test02 {

    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 0; i < 40; i++) {
            Student student = new Student();
            if (i < 9) {
                student.setSid("000" + (i + 1));
            } else {
                student.setSid("00" + (i + 1));
            }

            student.setName(RandomUtil.getName());
            student.setGender(RandomUtil.getGender());
            student.setBirthday(RandomUtil.getBirthday());
            student.setPhone(RandomUtil.getPhone());
            student.setWxs(RandomUtil.getWxs());
            student.setGroup(i / 4 + 1);
            //System.out.println(student);
            list.add(student);
        }
        //list


        for (Student student : list) {
            System.out.println(student);
        }
        System.out.println("=================");
        TreeSet<Student> set = new TreeSet<>(list);
        for (Student student : set) {

            System.out.println(student);
        }
        List<Student> oldest3 = set.stream().limit(3).collect(Collectors.toList());
        System.out.println("最老的三个:");
        for (Student student : oldest3) {
            System.out.println(student);
        }
        System.out.println("最嫩的三个:");
        List<Student> youngest3 = set.stream().skip(list.size() - 3).collect(Collectors.toList());
        for (Student student : youngest3) {

            System.out.println(student);
        }
        Student first = set.first();
        Student last = set.last();
        System.out.println("最老的:"+first);
        System.out.println("最嫩的:"+last);
        System.out.println(Period.between(first.getBirthday(), last.getBirthday()));


    }


}
